import React from 'react';

import get_sub_state from './get_sub_state';
import actions from './actions';
import {connect} from 'react-redux';

class MenuList extends React.Component{
    constructor(props){
        super(props);
    }
    render(){

        function times(html){
            let div = document.createElement('div');
            div.innerHTML = html;
            return div.textContent;
        }
        let lis = this.props.list.map((item)=>{
            return <li key={item.id} onClick={()=>this.props.select(item.id)} style={{backgroundColor: item.selected?"yellow":""}}>{item.name}</li>
        });

        let as = this.props.list2.map((item)=>{
            // if(item.selected){
                // let htmltime =  times("&times;");
                // let htmltime =  "关闭";
                return <a key={item.id} className={item.selected?"active":""} href="javascript:;">{item.name}<i onClick={()=>this.props.closeWindow(item.id)}>{times("&times;")}</i></a>
            // }
        });
        return <div>
            <ul style={{float:"left"}}>
                {lis}
            </ul>
            <p className={"currTabs"} style={{float:"left"}}>
                {as}
            </p>
        </div>;
    }
}

export default connect(get_sub_state, actions)(MenuList);
